const glob = require('glob')

function routersLoader (dirname){

    return new Promise((resolve, reject) =>{

        glob(

            `${dirname}/*`,

            {
                ignore: '**/index.js'
            },

            (err, filesPath) =>{

                if(err){ reject(err) }

                const routers = [];

                filesPath.forEach(path =>{
                    routers.push(require(path))
                })

                resolve(routers)
                
            }
            
        )
        
    })
    
}

module.exports = routersLoader